package org.codeart.reflect;

import org.codeart.singleton.Singleton05;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

/**
 * 使用反射破坏单例
 */
public class ReflectTest {

    public static void main(String[] args) throws NoSuchMethodException, InvocationTargetException,
            InstantiationException, IllegalAccessException {
        Class<Singleton05> clazz = Singleton05.class;
        Constructor<Singleton05> constructor = clazz.getDeclaredConstructor();
        constructor.setAccessible(true);
        Singleton05 instance1 = constructor.newInstance();
        Singleton05 instance2 = constructor.newInstance();
        System.out.println(instance1 == instance2);
    }
}
